<!-- 中心钱包余额 -->
<template> 
     <el-dialog
          title="中心钱包余额"
          :close-on-click-modal="false"
          :visible.sync="addFormVisible"
          width="90%" 
          @close="closeDialog"  
          v-if="addFormVisible"
        >  
        <div class=" "> 
            <div class="serachTop"> 
                <!-- 搜索筛选 -->
                <el-form :inline="true" :model="formInline" class="user-search">
                <el-form-item >
                    <el-input
                    size="small"
                    v-model="formInline.userId"
                    placeholder="输入用户ID"
                    type="number"
                    clearable
                    ></el-input>
                </el-form-item> 

                <el-form-item  >
                    <el-select v-model="formInline.balanceType" clearable placeholder="余额类型" size="small">
                        <el-option 
                            label="中心钱包"
                            value="balance">
                            </el-option>
                            <el-option 
                            label="共享卡钱包"
                            value="matrix_balance">
                            </el-option>
                    </el-select>  
                </el-form-item>

                <el-form-item  >
                    <el-select v-model="formInline.changeType" clearable placeholder="变动类型" size="small">
                        <el-option 
                            label="增加"
                            value="increase">
                        </el-option>
                        <el-option 
                            label="减少"
                            value="decrease">
                        </el-option> 
                    </el-select>  
                </el-form-item>  

                <el-form-item  > 
                     
                  <el-date-picker
                    v-model="value1"
                    size="small"
                    type="datetimerange"
                    value-format="timestamp"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    @change="createdData"
                  >
                  </el-date-picker>

                </el-form-item>  


                <el-form-item>
                    <el-button
                    size="small"
                    type="primary"
                    icon="el-icon-search"
                    @click="search"
                    >
                    搜索
                    </el-button>
                </el-form-item>
                <el-form-item>
                  <el-button size="small" type="primary" icon="el-icon-download" @click="exportEx()">
                      导出
                  </el-button>
                </el-form-item>
                
             </el-form>
         </div>
        
     
        <!--列表-->
        <div class="ra_box" style="width: 100%; max-height: 420px; overflow-y: auto;">
            <el-table
            size="small"
            :data="listData"
            highlight-current-row
            v-loading="loading"
            element-loading-text="拼命加载中"
            style="width: 100%; max-height: 420px; overflow-y: auto;"
            >
            <el-table-column prop="userId" label="用户ID" width="80">
            </el-table-column>
            
            <el-table-column
                prop="refType"
                label="业务类型"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column prop="balanceType" label="余额类型" show-overflow-tooltip>
                <template slot-scope="scope">
                    <div>{{ scope.row.balanceType=='balance'?'中心钱包':scope.row.balanceType=='matrix_balance'?'共享卡钱包':'-' }}</div>
                    <!-- balance:中心钱包；matrix_balance：共享卡钱包) -->
                </template>  
            </el-table-column>
            <el-table-column
                prop="changeAmount"
                label="变动金额"
                show-overflow-tooltip
            > 
                <template slot-scope="scope">
                    {{ b(scope.row.changeAmount) }}
                </template> 
            </el-table-column>
            <el-table-column
                prop="beforeBalance"
                label="变动前余额"
                show-overflow-tooltip
            > 
                <template slot-scope="scope">
                    {{ b(scope.row.beforeBalance) }}
                </template> 
            </el-table-column>
            <el-table-column
                prop="afterBalance"
                label="变动后余额"
                show-overflow-tooltip
            > 
                <template slot-scope="scope">
                    {{ b(scope.row.afterBalance) }}
                </template> 
            </el-table-column>
            <el-table-column
                prop="changeType"
                label="变动类型"
                show-overflow-tooltip
            > 
            <template slot-scope="scope">
                <div>{{ scope.row.changeType=='increase'?'增加':scope.row.changeType=='decrease'?'减少':'不变' }}</div>
                <!-- increase:增加；decrease：减少 -->
                </template>
            </el-table-column>
            <!-- <el-table-column
                prop="operatorName"
                label="操作人"
                show-overflow-tooltip
            >
            </el-table-column>  -->
            <el-table-column
                prop="createdAt"
                label="变动时间"
                show-overflow-tooltip
            >  
                <template slot-scope="scope">
                    {{ timestampToTime(scope.row.createdAt) || '-' }}
                </template>
            </el-table-column>
    
            <!-- <el-table-column
                prop="createdAtStart"
                label="开始时间"
                show-overflow-tooltip
            >
                <template slot-scope="scope">
                    {{ timestampToTime(scope.row.createdAtStart) || '-' }}
                </template>
            </el-table-column> 
            <el-table-column
                prop="createdAtEnd"
                label="截止时间"
                show-overflow-tooltip
            >
                <template slot-scope="scope">
                    {{ timestampToTime(scope.row.createdAtEnd) || '-' }}
                </template>
            </el-table-column>   -->
            
            </el-table>
        </div>
        <!-- 分页组件 -->
        <Pagination
            v-bind:child-msg="pageparm"
            @callFather="callFather"
        ></Pagination>
        </div> 
          
    </el-dialog>
</template>
<script>
import { mapState, mapGetters } from "vuex"; 
import {
  setStoreS,
  getStoreS,
  removeStoreS,
  insertCharacter,
  spStr,
  timestampToTime,
  timestampToData,
  timestampSubTime
  
} from "../../utils/util";
import {
  baseURL,
  req,
  reqJson,
  encrypt,
  decrypt,
  reqtoken,
  service,
  format,
  getUrl,
} from "../../api/axiosFun";
import Pagination from "../../components/Pagination"; 
export default {
  data() {
    return { 
      loading: false,
      disabled: false,
      addFormVisible: false, 
      titleZhuan:'转出',
      b: format, 
      timestampToTime:timestampToTime, 
      timestampToData:timestampToData,
      formInline: {
        pageNum: 1,
        pageSize: 10, 
      },
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10,
      },
  
      verArry:[],
      verType:'',
      curItem:'',
      options:[],
      userIDList:[],
      userBindList:[],
      value1:""

    };
  },
  props: ['visble','curItem'],
  emits: ['close'],
  // 注册组件
  components: {
    Pagination, 
  },
  computed: {
    ...mapGetters(["getUser"]), 
  },
  watch: {
    getUser(newVal) {
      this.userInfo = JSON.parse(newVal); 
    },
  }, 

  created() { 
    this.formInline.userId = this.curItem.userId
    this.getdata(this.formInline);  
    this.addFormVisible = this.visble
  },
  methods: { 
    closeDialog() {
       this.addFormVisible=false
       this.$emit('close',false);
    },    
    createdData() {
      if (this.value1) {
        this.formInline.createdAtStart = timestampSubTime(
          this.value1[0]
        );
        this.formInline.createdAtEnd = timestampSubTime(
          this.value1[1]
        );
      } else {
        this.formInline.createdAtStart = "";
        this.formInline.createdAtEnd = "";
      }
    },

    getdata(parameter) {    
        let obj = {
            ...parameter,
            id:this.curItem.userId,  
        }
      let url = getUrl(obj);    
      let apiUrl = '/api/admin/getBalanceChangeLogs' 
      if(this.userInfo&&(this.userInfo.userType == '01' || this.userInfo.userType=='02')){
        apiUrl = '/api/photon/getBalanceChangeLogs' 
      }    
      reqJson("get", apiUrl+url, {})
      .then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.listData = res.rows;
            this.pageparm.currentPage = this.formInline.pageNum;
            this.pageparm.pageSize = this.formInline.pageSize;
            this.pageparm.total = res.total;
          } else {
            this.$message({
              type: "info",
              message: res.msg,
            });
          }
        })
        .catch((err) => {
          this.loading = false;
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
        
    },
    exportEx() {
      let url = getUrl(this.formInline); 
      let apiUrl = '/api/admin/exportBalanceChangeLogs' 
      if(this.userInfo&&(this.userInfo.userType == '01' || this.userInfo.userType=='02')){
        apiUrl = '/api/photon/exportBalanceChangeLogs' 
      }    
      service
        .post(apiUrl+ url, {})
        .then((res) => {
          this.loading = false; 
          if (res.code == 0) {
            window.open(
              baseURL + "/common/download?fileName=" + res.msg,
              "_blank"
            );
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.loading = false;
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.pageNum = parm.currentPage;
      this.formInline.pageSize = parm.pageSize;
      this.getdata(this.formInline);
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline);
    }, 
    
  }, 

};
</script>

